package labox.innovation.gameserver.model.zone.type;

import labox.innovation.config.Config;
import labox.innovation.gameserver.model.actor.L2Character;
import labox.innovation.gameserver.model.zone.L2ZoneType;

/**
 * A Town zone
 *
 * @author  durgus
 */
public class L2TownZone extends L2ZoneType {
	private String _townName;

	private int _townId;

	private int _redirectTownId;

	private int _taxById;

	private boolean _isPeaceZone;

	private int[] _spawnLoc;

	public L2TownZone(int id) {
		super(id);

		_taxById = 0;
		_spawnLoc = new int[3];

		// Default to Giran
		_redirectTownId = 9;

		// Default peace zone
		_isPeaceZone = true;
	}

	@Override
	public void setParameter(String name, String value) {
		if (name.equals("name")) {
			_townName = value;
		} else if (name.equals("townId")) {
			_townId = Integer.parseInt(value);
		} else if (name.equals("redirectTownId")) {
			_redirectTownId = Integer.parseInt(value);
		} else if (name.equals("taxById")) {
			_taxById = Integer.parseInt(value);
		} else if (name.equals("spawnX")) {
			_spawnLoc[0] = Integer.parseInt(value);
		} else if (name.equals("spawnY")) {
			_spawnLoc[1] = Integer.parseInt(value);
		} else if (name.equals("isPeaceZone")) {
			_isPeaceZone = Boolean.parseBoolean(value);
		} else
			super.setParameter(name, value);
	}

	@Override
	protected void onEnter(L2Character character) {

		if (_isPeaceZone && Config.ZONE_TOWN != 2)
			character.setInsideZone(L2Character.ZONE_PEACE, true);

		character.setInsideZone(L2Character.ZONE_TOWN, true);

	}

	@Override
	protected void onExit(L2Character character) {
		// TODO: there should be no exit if there was possibly no enter
		if (_isPeaceZone)
			character.setInsideZone(L2Character.ZONE_PEACE, false);

		character.setInsideZone(L2Character.ZONE_TOWN, false);

		// if (character instanceof L2PcInstance)
		//((L2PcInstance)character).sendMessage("You left "+_townName);

	}

	@Override
	public void onDieInside(L2Character character) {
	}

	@Override
	public void onReviveInside(L2Character character) {
	}

	/**
	 * Returns this town zones name
	 * @return
	 */
	@Deprecated
	public String getName() {
		return _townName;
	}

	/**
	 * Returns this zones town id (if any)
	 * @return
	 */
	public int getTownId() {
		return _townId;
	}

	/**
	 * Gets the id for this town zones redir town
	 * @return
	 */
	@Deprecated
	public int getRedirectTownId() {
		return _redirectTownId;
	}

	/**
	 * Returns this zones spawn location
	 * @return
	 */
	public final int[] getSpawnLoc() {
		return _spawnLoc;
	}

	/**
	 * Returns this town zones castle id
	 * @return
	 */
	public final int getTaxById() {
		return _taxById;
	}

	public final boolean isPeaceZone() {
		return _isPeaceZone;
	}
}
